﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/05/27
 * 
 * 功能说明：功能模块的字段类型控件，单行文本控件
 * 
 * 修改人员：yylu
 * 
 * 修改日期：2009/08/20
 * 
 * 修改记录：1)增加控件手写单独使用的代码
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class UserControls_FieldControl_TextType : Whir.Controls.ModelField.BaseFieldControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Whir.BLL.Whir_FieldText bll = new Whir.BLL.Whir_FieldText();
        int fieldTextId = int.Parse(bll.GetList(" FieldID = " + this.FieldID).Tables[0].Rows[0][0].ToString());
        Whir.Model.Whir_FieldText model = bll.GetModel(fieldTextId);

        if (this.isSingleUse)
        {
            this.InitFieldControl(this.FieldID);
        }

        //设置控件的宽度
        if (!string.IsNullOrEmpty(model.textWidth))
            this.txtTextType.Width = int.Parse(model.textWidth);

        if (!IsPostBack)
        {
            int ItemID = NetRequest.GetQueryInt("ItemID");
            if (ItemID == 0)
            {
                //添加操作，绑定默认值
                if (model.defaultValue.IndexOf("@@") >= 0)
                {
                    if (model.defaultValue.ToLower() == "@@admintruename")
                    {
                        this.txtTextType.Text = RoleHelper.AdminCache.adminTrueName;
                    }
                    else if (model.defaultValue.ToLower() == "@@adminname")
                    {
                        this.txtTextType.Text = RoleHelper.AdminCache.adminName;
                    }
                    this.txtTextType.ReadOnly = true;
                }
                else
                {
                    this.txtTextType.Text = model.defaultValue;
                }                
            }
            else
            {
                if (model.defaultValue.IndexOf("@@") >= 0)
                {
                    if (model.defaultValue.ToLower() == "@@admintruename")
                    {
                        this.txtTextType.Text = RoleHelper.AdminCache.adminTrueName;
                    }
                    else if (model.defaultValue.ToLower() == "@@adminname")
                    {
                        this.txtTextType.Text = RoleHelper.AdminCache.adminName;
                    }
                    this.txtTextType.ReadOnly = true;
                }
                else
                {
                    //更新操作，绑定值
                    this.txtTextType.Text = FieldCommon.GetBindValue(this.FieldID, ItemID);
                }                
            }
            if (this.EnableNull)
            {
                this.rfvtxtTextType.Enabled = false;
                this.rfvtxtTextType.Visible = false;
            }
            else
            {
                this.rfvtxtTextType.IsValid = true;
                this.rfvtxtTextType.ErrorMessage = this.FieldAlias + "不能为空！";
            }
        }
        else
        {
            this.FieldValue = this.txtTextType.Text;
        }
    }
}
